% final version do not change these!
%%
%open text file from run_stuff
clear all
close all
clc
%%

%old tie points
%f=fopen('/Users/kimberlyhess/Harvard Paleomag Dropbox/Harvard Paleomag/QDM2_data/Speleothems/Onca/IRM1T_D/Bzcropped_profile.txt','r');

%Rogers
%f=fopen('/Users/kimberlyhess/Harvard Paleomag Dropbox/Harvard Paleomag/QDM2_data/Speleothems/Onca/IRM1T_D/Bz_profile.txt','r');

%with new tie points
f=fopen('/Users/kimberlyhess/Harvard Paleomag Dropbox/Harvard Paleomag/QDM2_data/Speleothems/Onca/IRM1T_D/Bzcropped_profile2.txt','r');

%with no cropping

%f=fopen('/Users/kimberlyhess/Harvard Paleomag Dropbox/Harvard Paleomag/QDM2_data/Speleothems/Onca/IRM1T_D/Bzprofile_nocrop.txt','r');

%from Antares no cropping

%f=fopen('/Users/mike/Dropbox/science/harvard/QDM2_data/Speleothems/Onca/IRM1T_D/Bzcropped_profile2.txt','r');

Bzcropped_profile2=textscan(f,'%f%f','Delimiter',' ','MultipleDelimsAsOne',1);

fclose('all');

%%
%compile BZ profile - make a new variable


BzProfile2croppedMerged=[Bzcropped_profile2{1,1},Bzcropped_profile2{1,2}];%created the variable
Bzcropped_profile2=BzProfile2croppedMerged; %create new variable named BzProfile2

%%
% %plot all bz profiles together
% figure
% hold on
% plot (BzProfile_Cropped(:, 1), BzProfile_Cropped(:,2))
% hold on 
% plot (BzProfile_nocrop(:, 1), BzProfile_nocrop(:,2))
% hold on
% plot (BzProfile_Rogers(:, 1), BzProfile_Rogers(:,2))
% hold on
% plot (BzProfile_antares(:, 1), BzProfile_antares(:,2))

%%
%create FOV counter
Bzcropped_profile2(:,4)=Bzcropped_profile2(:, 1);%create 4th col same as col 1
Fov=1;%  fov counter started
for i=1:size(Bzcropped_profile2, 1) %cycle through all the rows
    if ~(i==Bzcropped_profile2(i,1)) %if i=row number leave it alone
        jump=i-Bzcropped_profile2(i,1); %but if not if there is a difference between i and row number get that difference that = jump
        Bzcropped_profile2(i:end,1)=Bzcropped_profile2(i:end,1)+ jump; %go back and add row number consecutively with the jump delta
        Fov=Fov+1; %increase the FOV counter
    end
    Bzcropped_profile2(i,3)=Fov; %put new FOV count into col 3
end

 % col 1 - pixel counter - consecutive
 % col 2 - Bz field
 % col 3 - FOV count
 % col 4 - pixel counter with jumps in it
 
 %%
%deleting the jump
Bzcropped_profile2(:,5)=Bzcropped_profile2(:, 2);%create 5th col same as col 2 for comparison
i=1;
while i<=size(Bzcropped_profile2,1); %do the following to all rows of BzProfile2:
    if ~(i==Bzcropped_profile2(i,4)) %if i isn't the same as the pixel count...
        jump=i-Bzcropped_profile2(i,4); %calculate the discrepancy between i and the pixel count - call it jump
        Bzcropped_profile2(i:i+jump-1,:)=[];%delete all rows between i and i+jump
        
    end
   i=i+1;
end
%plot(BzProfile2(:,4),BzProfile2(:,2),'-b'); %plot 
    

 % col 1 - pixel counter - has jumps removed  and is not consecutive
 % col 2 - Bz field
 % col 3 - FOV count
 % col 4 - pixel counter with jumps removed so it is consecutive - with the
 % left side of maps removed. this is the global x
 % col 5 - pixel counter for time interpolation
%%
%plotting distinct FOV's

figure
hold on

for i=1:Bzcropped_profile2(end,3)
    plot(Bzcropped_profile2((Bzcropped_profile2(:,3)==i),4),Bzcropped_profile2((Bzcropped_profile2(:,3)==i),2),'color',[1 0 0]*mod(i,2));
end

%%


%%
% tie all matrices together using global geochron points
 % col 1 - pixel counter - has jumps 
 % col 2 - Bz field
 % col 3 - FOV count
 % col 4 - pixel counter with jumps removed so  it's consecutive
 % col 5 - copy of Bz file
 % col 6 copy of global pixel counter for time interpolation
% %interpolation
% %data (year, pixel value in col 4)
%tip of speleothem is 2016 +/-4
% from first slice, FOV 8, cropped X=407, global=  ~2008 +/- 2 yrs, pixel
% after deleting jump/global pixel = 3007
%from 3rd slice, FOV29, cropped x = 347, global=  ~1963 +/- 2years, pixel
% after deleting jump/global pixel = 10732

Bzcropped_profile2(:,6)=Bzcropped_profile2(:, 4);%create 6th col same as col 4 for comparison

ties=[2016 1;%
      2008 3007; % 
      1963 10732;%
      1913 24076;

];

for i=1:size(ties,1)-1
    Bzcropped_profile2(ties(i,2):ties(i+1,2),5)=linspace(ties(i,1),ties(i+1,1),ties(i+1,2)-ties(i,2)+1);
    
end
hold on
plot (Bzcropped_profile2(:, 5), Bzcropped_profile2(:,2))
%make linear vector between first age (i, 1) and second age (i+1, 1) then
%populate the array with end points

%%
%annual data
start_date = 1913;
end_date = 2016;

yearly_compiled_Bz = zeros((end_date - start_date+1), 2);
Bzcropped_profile2(:,6)=Bzcropped_profile2(:, 2); %create col 6 of BZ vals to be avg'd

for ii=1:size(yearly_compiled_Bz,1) %do the following all years of BzProfile2:
    tempAvgBz=[]; %create storeage Bz vals for each year
    for jj=1:size(Bzcropped_profile2,1)  % look at all the rows in col 5
        if Bzcropped_profile2(jj,5) >= (ii-1+start_date)
            if Bzcropped_profile2(jj,5) < (ii+start_date)
                tempAvgBz = [tempAvgBz Bzcropped_profile2(jj,6)];
            end
        end
    end
    yearly_compiled_Bz(ii,1)  = (ii-1+start_date);
    yearly_compiled_Bz(ii,2)  = mean(tempAvgBz);
    
    
end

%%
%binned Bz data using raw data
start_date = 1913;%1913
end_date = 2016;
binning = 2;
binned_Bz_raw_2 = zeros(ceil((end_date - start_date+1)/binning), 2);
Bzcropped_profile2(:,6)=Bzcropped_profile2(:, 2); %create col 6 of BZ vals to be avg'd
%need to adjust to make ceiling bin at the end with the remainder
%y=((floor((size(yearly_binned_compiled_Bz,1))/binning))*binning)+1

for ii=1:binning:end_date-start_date+1 %do the following all years of BzProfile2:
    %disp(ii-1+start_date)
    tempAvgBz=[]; %create storeage Bz vals for each binned year
    for jj=1:size(Bzcropped_profile2,1)  % look at all the rows in col 5
        if Bzcropped_profile2(jj,5) >= (ii-1+start_date)
            if Bzcropped_profile2(jj,5) < (ii+binning+start_date)
                    
                tempAvgBz = [tempAvgBz Bzcropped_profile2(jj,6)];
            end
        
        end
    end
    %kimy = (ii-1+start_date) : ii+start_date-1
    binned_Bz_raw_2((ii-1)/binning +1,1)  = (ii-1+start_date);
    binned_Bz_raw_2((ii-1)/binning +1,2)  = mean(tempAvgBz);
    %if ii-1+start_date == 1971
        tempAvgBz
        mean(tempAvgBz)
        
    end


figure

plot(binned_Bz_raw_2(:,1),yearly_binned_compiled_Bz(:,2))

%%
%%
%binned Bz data using yearly data
start_date = 1913;%1913
end_date = 2016;
binning = 4
binned_Bz = zeros(ceil((end_date - start_date+1)/binning), 2);
%Bzcropped_profile2(:,6)=Bzcropped_profile2(:, 2); %create col 6 of BZ vals to be avg'd
%need to adjust to make ceiling bin at the end with the remainder
%y=((floor((size(yearly_binned_compiled_Bz,1))/binning))*binning)+1
for ii=1:binning:end_date-start_date+1 %do the following all years of BzProfile2:
    disp(ii-1+start_date)
    tempAvgBz=[]; %create storeage Bz vals for each year
    for jj=1:size(yearly_compiled_Bz,1)  % look at all the rows in col 5
        if yearly_compiled_Bz(jj,1) >= (ii-1+start_date)
            if yearly_compiled_Bz(jj,1) < (ii+2+start_date)
                tempAvgBz = [tempAvgBz yearly_compiled_Bz(jj,2)];
            end
        end
    end
        

    binned_Bz((ii-1)/binning +1,1)  = (ii-1+start_date);
    binned_Bz((ii-1)/binning +1,2)  = mean(tempAvgBz);
end


%%


%% %%   

 

%%
%rain_total = [Year,total_mm];
%%
%Carbon_13 = [Depthmm, Age, C_13];
%%
%Oxygen_18=[Depthmm, Age, O_18];

%%
All_binned_4=[binned_rain_total,binned_Bz_1913];
%copy all binned - delete 0 fields
%%
%binned Rain data

start_date = 1913;
end_date = 2016;
binning = 2
binned_rain_total2 = zeros(ceil((end_date - start_date+1)/binning), 2);
%BzProfile2(:,6)=BzProfile2(:, 2); %create col 6 of BZ vals to be avg'd
%need to adjust to make ceiling bin at the end with the remainder
%y=((floor((size(yearly_binned_compiled_Bz,1))/binning))*binning)+1
for ii=1:binning:end_date-start_date+1 %do the following all years of BzProfile2:
    disp(ii-1+start_date)
    tempAvgRain=[]; %create storeage Bz vals for each year
    for jj=1:size(rain_total,1)  % look at all the rows in col 5
        if rain_total(jj,1) >= (ii-1+start_date)
            if rain_total(jj,1) < (ii+2+start_date)
                tempAvgRain = [tempAvgRain rain_total(jj,2)];
            end
        end
    end
    binned_rain_total2((ii-1)/binning +1,1)  = (ii-1+start_date);
    binned_rain_total2((ii-1)/binning +1,2)  = mean(tempAvgRain);
end

%plot(binned_rain_total(:,1),binned_rain_total(:,2))

%%
%annual bin Carbon data from Onca 2 1867-2016
start_date = 1867;
end_date = 2016;

Carbon_13_annual = zeros((end_date - start_date+1), 2);
Carbon_13(:,4)=Carbon_13(:, 3); %create col 4 of C-13 vals to be avg'd

for ii=1:size(Carbon_13_annual,1) %do the following all years of BzProfile2:
    tempAvgC=[]; %create storeage Bz vals for each year
    for jj=1:size(Carbon_13,1)  % look at all the rows in col 1
        if Carbon_13(jj,2) >= (ii-1+start_date)
            if Carbon_13(jj,2) < (ii+start_date)
                tempAvgC = [tempAvgC Carbon_13(jj,3)];
            end
        end
    end
    Carbon_13_annual(ii,1)  = (ii-1+start_date);
    Carbon_13_annual(ii,2)  = mean(tempAvgC);
end

%%
%annual bin O-18 data Onca 2

start_date = 1867;
end_date = 2016;

Oxygen_18_annual = zeros((end_date - start_date+1), 2);
Oxygen_18(:,4)=Oxygen_18(:, 3); %create col 4 of C-13 vals to be avg'd

for ii=1:size(Oxygen_18_annual,1) %do the following all years of BzProfile2:
    tempAvgO=[]; %create storeage Bz vals for each year
    for jj=1:size(Oxygen_18,1)  % look at all the rows in col 1
        if Oxygen_18(jj,2) >= (ii-1+start_date)
            if Oxygen_18(jj,2) < (ii+start_date)
                tempAvgO = [tempAvgO Oxygen_18(jj,3)];
            end
        end
    end
    Oxygen_18_annual(ii,1)  = (ii-1+start_date);
    Oxygen_18_annual(ii,2)  = mean(tempAvgO);
end
%%
% 4 year binned O_18 onca 2 data

start_date = 1913;
end_date = 2016;
binning = 4
binned_O_18_4yr = zeros(ceil((end_date - start_date+1)/binning), 2);
%BzProfile2(:,6)=BzProfile2(:, 2); %create col 6 of BZ vals to be avg'd
%need to adjust to make ceiling bin at the end with the remainder
%y=((floor((size(yearly_binned_compiled_Bz,1))/binning))*binning)+1
for ii=1:binning:end_date-start_date+1 %do the following all years of BzProfile2:
    disp(ii-1+start_date)
    tempAvgO_18=[]; %create storeage Bz vals for each year
    for jj=1:size(Oxygen_18_annual,1)  % look at all the rows in col 5
        if Oxygen_18_annual(jj,1) >= (ii-1+start_date)
            if Oxygen_18_annual(jj,1) < (ii+2+start_date)
                tempAvgO_18 = [tempAvgO_18 Oxygen_18_annual(jj,2)];
            end
        end
    end
    binned_O_18_4yr((ii-1)/binning +1,1)  = (ii-1+start_date);
    binned_O_18_4yr((ii-1)/binning +1,2)  = mean(tempAvgO_18);
end

%plot(binned_O_18(:,1),binned_O_18(:,2))

%%
% 4 year binned C_13 onca 2 data

start_date = 1913;
end_date = 2016;
binning = 4
binned_C_13_4yr = zeros(ceil((end_date - start_date+1)/binning), 2);
%BzProfile2(:,6)=BzProfile2(:, 2); %create col 6 of BZ vals to be avg'd
%need to adjust to make ceiling bin at the end with the remainder
%y=((floor((size(yearly_binned_compiled_Bz,1))/binning))*binning)+1
for ii=1:binning:end_date-start_date+1 %do the following all years of BzProfile2:
    disp(ii-1+start_date)
    tempAvgC_13=[]; %create storeage Bz vals for each year
    for jj=1:size(Carbon_13_annual,1)  % look at all the rows in col 5
        if Carbon_13_annual(jj,1) >= (ii-1+start_date)
            if Carbon_13_annual(jj,1) < (ii+2+start_date)
                tempAvgC_13 = [tempAvgC_13 Carbon_13_annual(jj,2)];
            end
        end
    end
    binned_C_13_4yr((ii-1)/binning +1,1)  = (ii-1+start_date);
    binned_C_13_4yr((ii-1)/binning +1,2)  = mean(tempAvgC_13);
end

%plot(binned_C_13(:,1),binned_C_13(:,2))
%%
close all
figure
hold on
subplot(3,1,1)
x=Bzcropped_profile2(:,5);
y1=(Bzcropped_profile2(:,2));
plot(x, y1,'Linewidth', 2)
xlim([1913 2016])
title('bz raw')

subplot(3,1,2); 
x3 = (yearly_compiled_Bz(:,1));
y3 = ((yearly_compiled_Bz(:,2)*1e8));
plot(x3,y3, 'Linewidth', 2)
title('Magnetization')
xlim([1913 2016])
xlabel('Years')
ylabel('bz 1 year')



subplot(3,1,3); 
y2 = ((binned_Bz_raw(:,2)*1e8));
x2=(binned_Bz_raw(:,1));
plot(x2,y2, 'Linewidth', 2)
title('bz 4 year')
xlim([1913 2016])
xlabel('Years')
ylabel('bz 4 yr')

%%
close all
figure
hold on


hold on
x2=(yearly_compiled_BzCopy(:,3));
y2=(abs(yearly_compiled_BzCopy(:,2)*1e11));
plot(x2,y2, 'Linewidth', 4)
%subplot(4,1,1); 
x3 = (yearly_compiled_Bz(:,1));
y3 = (abs(yearly_compiled_Bz(:,2)*1e11));
plot(x3,y3, 'Linewidth', 1)
hold on
%subplot(4,1,2); 
x1 = (rain_total(:,1));
y1 = (rain_total(:,2));
plot(x1,y1, 'Linewidth', 2)




%%
%plot O18 C rain and bz
%close all
figure
hold on

%1  
subplot(4,1,1)
x=binned_rain_total(:,1);
y1= (abs(binned_Bz_raw4(:,2)*1e8)) ;
plot(x, y1,'Linewidth', 2)
xlim([1913 2016])
title('Magnetization')
xlabel('Years')
ylabel('magnetization')

%2
subplot(4,1,2); 
y2 = binned_rain_total(:,2);
plot(x,y2, 'Linewidth', 2)
title('rain')
xlim([1913 2016])
xlabel('Years')
ylabel('mm rain')

%3
subplot(4,1,3)
x=binned_rain_total(:,1);
y3=binned_O_18(:,2);
plot(x, y3,'Linewidth', 2)
xlim([1913 2016])
title('O_18')
xlabel('Years')
ylabel('O_18')

%4
subplot(4,1,4); 
y4 = (binned_C_13(:,2));
plot(x,y4, 'Linewidth', 2)
title('C_13')
xlim([1913 2016])
xlabel('Years')
ylabel('C-13')
%%
%plot O18 C rain and bz vertically for publication - 4 year
%close all
figure (9)
hold on

%1
subplot(1, 4,1)
y=binned_rain_total4(:,1);
x1= (binned_Bz_raw4(:,2));
plot(x1, y,'Linewidth', 2)
% hold on
% x7=(Bzcropped_profile2(:,6)/min(Bzcropped_profile2(:,6)))
% y2=(Bzcropped_profile2(:,5))
% plot(x7, y2)
% hold on
% y3=(binned_Bz_raw_median4(:,1))
% x8=(binned_Bz_raw_median4(:,2)/(binned_Bz_raw_median4(:,2)))
% plot(x8, y3)
ylim([1913 2016])
title('Magnetization')
xlabel('Bz')
ylabel('years')

%2
subplot(1,4,2); 
x2 = binned_rain_total4(:,2);
plot(x2,y, 'Linewidth', 2)
title('rain')
ylim([1913 2016])
xlabel('mm rain')
ylabel('years')

%3
subplot(1,4,3)
y=binned_O_18_4yr(:,1);
x3=binned_O_18_4yr(:,2);
plot(x3, y,'Linewidth', 2)
ylim([1913 2016])
title('O18')
xlabel('O18')
ylabel('years')

%4
subplot(1,4,4); 
y=binned_C_13_4yr(:,1);
x4 = (binned_C_13_4yr(:,2));
plot(x4,y, 'Linewidth', 2)
title('C_13')
ylim([1913 2016])
xlabel('C13')
ylabel('years')

%%

%%
%plot O18 C rain and bz vertically for publication - 2 year
%close all
figure (8)
hold on

%1
subplot(1, 4,1)
y=binned_rain_total2(:,1);
x1= abs(binned_Bz_raw2(:,2));
plot(x1, y,'Linewidth', 2)
% hold on
% x7=(Bzcropped_profile2(:,6)/min(Bzcropped_profile2(:,6)))
% y2=(Bzcropped_profile2(:,5))
% plot(x7, y2)
% hold on
% y3=(binned_Bz_raw_median4(:,1))
% x8=(binned_Bz_raw_median4(:,2)/(binned_Bz_raw_median4(:,2)))
% plot(x8, y3)
ylim([1913 2016])
title('Magnetization')
xlabel('Bz')
ylabel('years')

%2
subplot(1,4,2); 
x2 = binned_rain_total2(:,2);
plot(x2,y, 'Linewidth', 2)
title('rain')
ylim([1913 2016])
xlabel('mm rain')
ylabel('years')

%3
subplot(1,4,3)
y=binned_O_18_2yr(:,1);
x3=binned_O_18_2yr(:,2);
plot(x3, y,'Linewidth', 2)
ylim([1913 2016])
title('O18')
xlabel('O18')
ylabel('years')

%4
subplot(1,4,4); 
y=binned_C_13_2yr(:,1);
x4 = (binned_C_13_2yr(:,2));
plot(x4,y, 'Linewidth', 2)
title('C_13')
ylim([1913 2016])
xlabel('C13')
ylabel('years')
%%

%O_18 regression with bz


%mdl=fitlm((binned_Bz(:,2)*1e8),binned_O_18(:,2))
mdl=fitlm(Oxygen_18_annual(:,2), (yearly_compiled_Bz(:,2)*1e8))
%mdl=fitlm(binned_O_18(:,2), (binned_Bz(:,2)*1e8))
figure
title('Regression:O_18 and Total Magnetization')
xlabel('Bulk Magnetization')
ylabel('O-18')
plot(mdl)

%%
%regression O-18 to precipitation
mdl=fitlm((binned_O_18(:,2)),binned_rain_total(:,2))

figure
title('Regression:O18 and Precipitation')
xlabel('O18')
ylabel('Rain')
plot(mdl)

%%
subplot(2,1,1);
x = linspace(0,10);
y1 = sin(x);
plot(x,y1)

subplot(2,1,2); 
y2 = sin(5*x);
plot(x,y2)



%%
% plot 2 year binned Bz using raw Bz binning and rain
%close all

figure 
hold on
plot(binned_Bz_raw2(:,1),(abs(binned_Bz_raw2(:,2))),'-k','LineWidth',2)
yyaxis right
plot(binned_rain_total2(:,1),binned_rain_total2(:,2),'-b','LineWidth',2)
%%
% regression analysis 2 year binned Bz using raw Bz binning and rain

figure (1)
mdl=fitlm(abs(binned_Bz_raw2(:,2)*1e8),binned_rain_total2(:,2))
title('Regression:Precipitation and Total Magnetization 2 year binning')
xlabel('Bulk Magnetization')
ylabel('Precipitation')
plot(mdl)

%%
%plot 4 year binned raw Bz and 4 year binned rain
figure 
hold on
plot(binned_Bz_raw4(:,1),(abs(binned_Bz_raw4(:,2))),'-k','LineWidth',2)
yyaxis right
plot(binned_rain_total4(:,1),binned_rain_total4(:,2),'-b','LineWidth',2)
%%
%%
% regression analysis 4 year binned Bz using raw Bz binning and rain

figure (4)
mdl2=fitlm(abs(binned_Bz_raw4(:,2)*1e8),binned_rain_total4(:,2))
title('Regression:Precipitation and Total Magnetization 2 year binning')
xlabel('Bulk Magnetization')
ylabel('Precipitation')
plot(mdl2)

%%
%regression with median 4 year

mdl=fitlm(abs(binned_Bz_raw_median4(:,2)*1e8),binned_rain_total4(:,2))

figure
title('Regression:Annual Precipitation and Total Magnetization Median')
xlabel('Bulk Magnetization')
ylabel('Precipitation')
plot(mdl)

%%
%regerssion analysis annual Bz and annual rain

mdl=fitlm(abs(yearly_compiled_Bz(:,2)*1e8),rain_total(:,2))

figure
title('Regression:Annual Precipitation and Total Magnetization')
xlabel('Bulk Magnetization')
ylabel('Precipitation')
plot(mdl)

%%
%regression just to 1961
mdl=fitlm((binned_Bz_rawCopy(:,2)*1e8),binned_rain_totalCopy(:,2))

figure
title('Regression:Annual Precipitation and Total Magnetization')
xlabel('Bulk Magnetization')
ylabel('Precipitation')
plot(mdl)


%%

myFit = LinearModel.fit((All_binned_4_rgrs(:,4)*1e8),All_binned_4_rgrs(:,2));
plot(myFit)
%%



 folders=[
%     '/Users/Lia/Lia Kiam Dropbox/Lia Kiam/EPS-174_speleothem/Indios/IDSB1/FOV15/';
%      '/Users/kimberlyhess/Harvard Paleomag Dropbox/Harvard Paleomag/EPS_174_speleothem/Indios/IDSB1/FOV02/';
      '/Users/kimberlyhess/Harvard Paleomag Dropbox/Harvard Paleomag/QDM2_data/Speleothems/Onca/IRM1T_D/FOV19';
       ];
for i = 1:size(folders,1)
    file=[folders(i,:) '/Bz_uc0.mat'];
    load(file);
    filepartslocal=strsplit(file,'/');
    figure
    imagesc(newLED)
    caxis([-1 1]*max(abs(caxis)));
    %caxis([-1 1]*1e-6);
    axis xy, axis equal, axis tight, axis off
    title(filepartslocal(end-1))
    hh=colorbar;
    colormap(gray);
end

%%

 folders=[
%     '/Users/Lia/Lia Kiam Dropbox/Lia Kiam/EPS-174_speleothem/Indios/IDSB1/FOV15/';
%      '/Users/kimberlyhess/Harvard Paleomag Dropbox/Harvard Paleomag/EPS_174_speleothem/Indios/IDSB1/FOV02/';
      '/Users/kimberlyhess/Harvard Paleomag Dropbox/Harvard Paleomag/QDM2_data/Speleothems/Onca/IRM1T_D/FOV55';
       ];
figure
file=[folders() '/Bz_uc0.mat'];
load(file);
imagesc(Bz)

%caxis([-1 1]*max(abs(caxis)));
caxis([-1 1]*1e-6);
axis xy, axis equal, axis tight, axis off
hh=colorbar;
colormap(jet);




%%
%bz plot
%figure
plot(Bzcropped_profile2(:,5),abs(Bzcropped_profile2(:,6)), 'Linewidth', 1)
title('Magnetization over time - Onca')
xlabel('time')
xlim([1913 2016])
ylabel('Bulk Magnetization')


%%
plot(Bzcropped_profile2(6964:7650,5),Bzcropped_profile2(6964:7650,6))
%%
%plotting fields of view for comparison
close all

figure (1)


%1



y=Bz_39(:,4);
x1= Bz_39(:,3);
plot(x1, y,'Linewidth', 2)
title('39')
xlabel('time')
ylabel('Bz')

%2
figure (2)

y=Bz_52(:,4);
x1= Bz_52(:,3);
plot(x1, y,'Linewidth', 2)
title('52')
xlabel('time')
ylabel('Bz')
%4
figure (3); 
y=Bz_55(:,4);
x1= Bz_55(:,3);
plot(x1, y,'Linewidth', 2)
title('55')
xlabel('time')
ylabel('Bz')

figure (4)
hold on
plot((Bz_39(:,4)),'-k','LineWidth',2)
yyaxis right
plot((Bz_52(:,4)),'-b','LineWidth',2)
legend

%%
close all
figure
plot(Bzcropped_profile2(7397:11136,5),Bzcropped_profile2(7397:11136,2))